n = int(input())  # n行n列
mp = []  # 地图信息
for i in range(n):
    row = list(map(int, input().split()))
    mp.append(row)
dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]  # 上下左右，偏移量
cnt = 0


# 从位置p开始深搜
def backtracking(p):
    global n, mp, dir, cnt
    if p[0] == 0 and p[1] == n - 1:  # 到达终点右上角
        cnt += 1
        return
    pnew = [0, 0]
    # 从当前位置开始向4个方向搜索
    for i in range(4):
        pnew[0] = p[0] + dir[i][0]  # 行
        pnew[1] = p[1] + dir[i][1]  # 列
        if pnew[0] >= 0 and pnew[0] < n and \
                pnew[1] >= 0 and pnew[1] < n and mp[pnew[0]][pnew[1]] == 0:
            mp[pnew[0]][pnew[1]] = 1  # 当前位置设置为墙
            backtracking(pnew)  # 继续搜索
            mp[pnew[0]][pnew[1]] = 0


mp[0][0] = 1  # 起点已经走过了，改成墙
backtracking([0, 0])
print(cnt)
